package com.kczd.jinlan.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechUtility;
import com.kczd.jinlan.R;
import com.kczd.jinlan.voice.AudioRecorderButton;

/**
 * 搜索页面
 */
public class SearchClassifyActivity extends AppCompatActivity implements View.OnLayoutChangeListener{

    public static Context context;

    //Activity最外层的Layout视图
    private View activityRootView;
    //屏幕高度
    private int screenHeight = 0;
    //软件盘弹起后所占高度阀值
    private int keyHeight = 0;

    private AudioRecorderButton mYuyin;

    public SearchClassifyActivity()
    {
        this.context=this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_classify);
        SpeechUtility.createUtility(this, SpeechConstant.APPID + "=58d87d3a");

        mYuyin= (AudioRecorderButton) findViewById(R.id.imageView5);

        activityRootView = findViewById(R.id.activity_yuyin_search);
        //获取屏幕高度
        screenHeight = this.getWindowManager().getDefaultDisplay().getHeight();
        //阀值设置为屏幕高度的1/3
        keyHeight = screenHeight/3;
    }
    @Override
    public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
        //现在认为只要控件将Activity向上推的高度超过了1/3屏幕高，就认为软键盘弹起
        if(oldBottom != 0 && bottom != 0 &&(oldBottom - bottom > keyHeight)){
            mYuyin.setVisibility(View.GONE);

        }else if(oldBottom != 0 && bottom != 0 &&(bottom - oldBottom > keyHeight)){

            mYuyin.setVisibility(View.VISIBLE);
        }
    }
    @Override
    protected void onResume() {
        super.onResume();

        //添加layout大小发生改变监听器
        activityRootView.addOnLayoutChangeListener(this);
    }

}
